from pydantic import BaseSettings, Field


class AuthSettings(BaseSettings):
    """认证相关配置"""
    secret_key: str = Field('09d25e094faa6ca2', title='skey', description='token加密字段')
    algorithm: str = Field('HS256', title='算法', description='token生成算法')
    expire: int = Field(28800, title='过期时间(hour)', description='token生成到过期时间 8H')
    token_url: str = Field('/api/v1/auth/token', title='认证接口', description='获取token接口')

    rsa_public: str = Field(
        'LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JR0pBb0dCQUk2dWNEVGh6TGRGTitqMll5R0ZUNDNiRXBrK2NNWHFra1JDZmR3alhLSEJGT1hLSTg0bHJwUlQKblNlSU4vcCtXT0NCdUtmaC9aNHJsa05XYk4zdXUzZXJXa25SbjNEdVJIQlZGcmYxOU9Od3FPOW5zL2l5Vm5kRApDNVdFVTFRZU55QjBGTGUyRVRkVlppYmROc0liMVlOYUNQVWtQQ3JWbisvQ0RZYThuUE05QWdNQkFBRT0KLS0tLS1FTkQgUlNBIFBVQkxJQyBLRVktLS0tLQo=',
        title='加密公钥')
    rsa_private: str = Field(
        'LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlDWUFJQkFBS0JnUUNPcm5BMDRjeTNSVGZvOW1NaGhVK04yeEtaUG5ERjZwSkVRbjNjSTF5aHdSVGx5aVBPCkphNlVVNTBuaURmNmZsamdnYmluNGYyZUs1WkRWbXpkN3J0M3ExcEowWjl3N2tSd1ZSYTM5ZlRqY0tqdlo3UDQKc2xaM1F3dVZoRk5VSGpjZ2RCUzN0aEUzVldZbTNUYkNHOVdEV2dqMUpEd3ExWi92d2cyR3ZKenpQUUlEQVFBQgpBb0dBRXROVFBMYjZNc2d3TzAyZkFNSTlIK05pemROZVA4N1dZNmsrUC9odWRXMHJXN0pURFJVTnRzWmRldVRQCk5mN0xyVHVRYUo0NXYwL1M4S21MZVJNRnJsUzQ3S2ZLOFFHOFM4Rzk3SEZGazdjKzZRdlNEUDJ3dGM5Y2J0OVEKdHg2TVJJQ0tMZnMvV25UbS9xaUZhNWRsTnBWVlB4NmtrUWhBSndjWnFTNTh3TUVDUlFDY1FLaUorN2wxbEs1dApweFRFNkZ1STVHc0VIVC9RL3NpMm0zbDhOMWdINEZmb2YvcG5UQVpqMldxK3cvcyt2MVFVLzlkQXRZazNSaFN5CmNXSXRabkhlRXR4bGNRSTlBT25EN25xT3JURXZ2bUF3SC9lU2o0MHRVRllyM1FHT3A1T2NNWFJoWWFYN1c2WUoKSC9TV0FVaTVPVGhDSnhneWhHM0RnYW51RS9FbXp2QlVqUUpFUjlCcjVlYzlDTzZKOExuUEVPVWVWTjl1MUJoQgpZV1FJaWUwUk8rY1AzYWJkb0cxWmdDcHY4V3BXNWxDYTQrNzV6U0Q5SksrSzNrMm1hNUV6SjF5alR3YnFKdkVDClBCUTdTT0NDaUtyQkh4RGtHV0FyNXhDbzQxTVI2TWJCdWU4a2pZTXRDbTU3R3F0OERxLzBhNWdIcjlRV3BadUsKZzd1Y09CU2s3a1RvdnZBOTRRSkZBSk1kUDdpZ09rUFJYeUkyR1hrNWRJSnh2aHZTalJrcS9makxMMzRTNGx5agpaaU1leUYzYTRSOFRZQnE1aGpWMWZPUzJIZmJzVXgvdkttaVZuWU42REhabEFaamQKLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0K',
        title='加密私钥')


class SchedulerSettings(BaseSettings):
    scheduler_pool: int = Field(10, title='定时任务线程池')
    scheduler_coalesce: bool = Field(True, title='定时任务是否合并')
    scheduler_max_instances: int = Field(3, title='定时任务最大实例数')


class BusinessSettings(BaseSettings):
    """业务数据配置"""
    audit_topic: str = Field('system_audit_log', title='审计topic')
    alert_topic: str = Field('system_warning_log', title='告警topic')

    audit_model: str = Field('system_audit_log', title='系统审计日志')
    alert_model: str = Field('system_warning_log', title='系统告警日志')


class Setting(AuthSettings, BusinessSettings, SchedulerSettings):
    """项目配置信息 从consul里获取"""
    prod: bool = Field(True, title='生产环境')
    kafka_servers: str = Field('broker:9092', title='kafka连接')
    kafka_options: dict = Field({}, title='账号密码等', 
                                exmaple={'sasl.username': '', 'sasl.password': '', 
                                         'security.protocol': 'SASL_PLAINTEXT', 'sasl.mechanism': 'PLAIN'})

    pg_uri: str = Field('postgresql+psycopg2://system:system@postgres:5432/system', title='数据库')

    elasticsearch_hosts: list = Field([{'host': 'elasticsearch', 'port': 9200}], title='主机 可能是集群')
    elasticsearch_auth: list = Field(None, title='elasticsearch账号密码')

    redis_host: str = Field('redis', title='redis主机')
    redis_port: int = Field(6379, title='redis端口', env='redis_port_')
    redis_password: str = Field('MY.io2019', title='redis密码')

    version: str = Field('3.0.2409.1', title='产品版本')
    homepage: str = Field('https://miaoyun.net.cn/', title='公司主页')
    admin_password: str = Field('admin', title='管理员密码 初始化时生效')

    class Config:
        extra = 'ignore'
        env_file = '.env'


setting = Setting()

if __name__ == '__main__':
    print(setting.dict())
